# 用类封装一个`MyMath`类, 实现加, 减, 乘, 除, 幂, 开方
# 静态方法练习
class ParamsError(Exception):
    pass

class MyMath:
    @staticmethod
    def add(a, b):
        print("做加法，结果：")
        return a + b
    @staticmethod
    def sub(a, b):
        print("做减法，结果：")
        return a - b
    def mul(self,a, b):
        print("做乘法，结果：")
        return a * b
    def div(self,a, b):
        try:
            print("做除法，结果：")
            return a / b
        except ZeroDivisionError:
            raise ParamsError("除法中，分母不能为0")
        finally:
            print("div end")

    def intdiv(self,a, b):
        try:
            print("整除结果：")
            return a // b
        except ZeroDivisionError:
            raise ParamsError("除法中，分母不能为0")
        finally:
            print("intdiv end")

    def yu(self,a, b):
        print("余数：")
        return a % b

    def sqrt(self,a):
        print("平方根计算结果是：")
        return float(a ** (1/2))





if __name__=="__main__":
    print("1加法，2减法，3乘法，4除法，5整除，6取余，7平方根")
    m=MyMath()
    try:
        n = int(input("请输入对应数字，选择计算方法:"))
    except Exception as e:
        print(e)
        print("您选择的计算方法有误。！")
    else:
        iList = [1, 2, 3, 4, 5, 6, 7]
        if n in iList:
            if n == 7:
                m1 = int(input("请输入一个数字："))
                print(m.sqrt(m1))
            else:
                m1 = int(input("请输入第一个数字："))
                m2 = int(input("请输入第二个数字："))
                if n == 6:
                    print(m.yu(m1, m2))
                elif n == 5:
                    print(m.intdiv(m1, m2))
                elif n == 4:
                    print(m.div(m1, m2))
                elif n == 3:
                    print(m.mul(m1, m2))
                elif n == 2:
                    print(MyMath.sub(m1, m2))
                elif n == 1:
                    print(MyMath.add(m1, m2))
        else:
            print("您选择的计算方法有误。-------")
